//导入
var express=require('express')


//创建子路由对象
var goodRouter=express.Router()

// var arr = [
//     { email: '178884773@qq.com', name: '张伟', phone: '13611129070', pass: '1234', ingroup: '编辑组', isadmin: true, status: true },
//     { email: '178884773@qq.com', name: '李煜', phone: '13611129070', pass: '1234', ingroup: '编辑组', isadmin: true, status: true },
//     { email: '178884773@qq.com', name: '李清照', phone: '13611129070', pass: '1234', ingroup: '编辑组', isadmin: true, status: false },
//     { email: '178884773@qq.com', name: '李浩', phone: '13611129070', pass: '1234', ingroup: '编辑组', isadmin: true, status: true },
//     { email: '178884773@qq.com', name: '大锤', phone: '13611129070', pass: '1234', ingroup: '编辑组', isadmin: true, status: true },
//     { email: '178884773@qq.com', name: '子怡', phone: '13611129070', pass: '1234', ingroup: '编辑组', isadmin: true, status: false },
//     { email: '178884773@qq.com', name: '海洛', phone: '13611129070', pass: '1234', ingroup: '编辑组', isadmin: true, status: true },
//     { email: '178884773@qq.com', name: '崽崽', phone: '13611129070', pass: '1234', ingroup: '编辑组', isadmin: true, status: false },
//     { email: '178884773@qq.com', name: '奶糖', phone: '13611129070', pass: '1234', ingroup: '编辑组', isadmin: true, status: false }
// ]

//req  请求对象，包含本次请求相关的信息
//res  响应请求，可以借助res向客户端返回信息
//分页
goodRouter.get('/list', (req, res) => {
    var { page,count } = req.query;
  

    //分页
    //slice 选取
    var newarr = arr.slice((page - 1) * count, page * count)
    //返回数据

    // console.log('收到了来自客户端的请求');
    res.send({ code: 200, msg: '请求成功',list: newarr})
})

//搜索
goodRouter.get( '/search', (req,res)=>{
    //接收参数
    var { searchkey } = req.query;
    var newarr = arr.filter((item)=>{
        return item.name.indexOf(searchkey) != -1
        
    })
    //返回数据
    res.send({ code:200,msg:'查询成功!',list:newarr })
})


//导出
module.exports=goodRouter;